package com.xy.xymall.order.controller;

import com.xy.xymall.order.entity.OrderEntity;
import com.xy.xymall.order.entity.OrderItemEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author XY
 * @version 1.0.0
 * @ClassName RabbitController.java
 * @createTime 2020年11月02日 19:55:00
 */
@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "num",defaultValue = "10") Integer num){
        for(int i=0;i<num;i++){
            if(i%2==0){
                OrderItemEntity orderItemEntity = new OrderItemEntity();
                orderItemEntity.setSkuName("哈哈:"+i);
                orderItemEntity.setId(11L);
                rabbitTemplate.convertAndSend("hello-java-exchange","key",orderItemEntity,new CorrelationData(UUID.randomUUID().toString()));
            }else{
                OrderEntity orderEntity=new OrderEntity();
                orderEntity.setReceiverName("wowowow:"+i);
                rabbitTemplate.convertAndSend("hello-java-exchange","key",orderEntity,new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "ok";
    }

}
